package com.example.leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Code17 {
    public static void main(String[] args) {
        // System.out.println((char) (c + 1));
        String str1 = "abc";
        String str2 = "def";
        String str3 = "ghi";
        for (int i = 0; i < str1.length(); i++) {
            //builder1.append(str1.charAt(i));
            for (int j = 0; j < str2.length(); j++) {
                //builder1.append(str2.charAt(j));
                StringBuilder builder2 = new StringBuilder();

                for (int k = 0; k < str3.length(); k++) {
                    String builder1 = String.valueOf(str1.charAt(i)) +
                            str2.charAt(j) +
                            str3.charAt(k);
                    System.out.println(builder1);
                    //builder1 = new StringBuilder();
                }
            }
        }
//        String str = "A";
//        String str1 = 1 + "A";
//        System.out.println(str1);
//        System.out.println(map);
        Code17 code17 = new Code17();
        System.out.println(code17.letterCombinations("289"));
    }

    /**
     * todo  不简单！
     *
     * @param digits
     * @return
     */
    public List<String> letterCombinations(String digits) {
        Map<String, List<String>> map = new HashMap<>();
        char c = 'A';
        List<String> list = null;
        // 构造对应的关系
        for (int i = 2; i < 10; i++) {
            list = new ArrayList<>();
            list.add(String.valueOf(c++));
            list.add(String.valueOf(c++));
            list.add(String.valueOf(c++));
            if (i == 7 || i == 9) {
                list.add(String.valueOf(c++));
            }
            map.put(String.valueOf(i), list);
        }
        char[] chars = digits.toCharArray();
        for (char aChar : chars) {
            List<String> list1 = map.get(String.valueOf(aChar));
//            for (int i = 0; i < list1.size(); i++) {
//
//            }
        }
        //


        List<String> list0 = chars.length >= 1 ? map.get(String.valueOf(chars[0])) : new ArrayList<>();
        List<String> list1 = chars.length >= 2 ? map.get(String.valueOf(chars[1])) : new ArrayList<>();
        List<String> list2 = chars.length >= 3 ? map.get(String.valueOf(chars[2])) : new ArrayList<>();
        List<String> list3 = chars.length >= 4 ? map.get(String.valueOf(chars[3])) : new ArrayList<>();
        List<String> ans = new ArrayList<>();
        for (int i = 0; i < list0.size(); i++) {
            for (int j = 0; j < list1.size(); j++) {
                for (int k = 0; k < list2.size(); k++) {
                    for (int l = 0; l < list3.size(); l++) {
                        System.out.println("hello world");
                    }
                }
            }
        }
        for (String s0 : list0) {
            StringBuilder str = new StringBuilder();
            str.append(s0);
            if (chars.length == 1) {
                ans.add(str.toString());
                str = new StringBuilder();
            }
            for (String s1 : list1) {
                str.append(s1);
                if (chars.length == 2) {
                    ans.add(str.toString());
                    str = new StringBuilder();
                }
                for (String s2 : list2) {
                    str.append(s2);
                    if (chars.length == 3) {
                        ans.add(str.toString());
                        str = new StringBuilder();
                    }
                    for (String s3 : list3) {
                        str.append(s3);
                        if (chars.length == 4) {
                            ans.add(str.toString());
                            str = new StringBuilder();
                        }
                    }
                }
            }
        }
        return ans;
    }
}
